package com.zcq.jpush;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;

public class JPushClientDemo {
	private final static Logger LOG = LoggerFactory.getLogger(JPushClientDemo.class);
	private final static String appKey = "ac49047c8c8b35223fcf261e";
	private final static String masterSecret = "95711b9b2d6a6afd56dc315d";
	
	public static void main(String[] args) {
		Jdpush.testSendPush(appKey, masterSecret);
		/*JPushClient jpushClient = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
	    PushPayload payload = buildPushObject_all_all_alert("hello jpush !");
	    try {
	        PushResult result = jpushClient.sendPush(payload);
	        System.out.println("Got result - " + result);
	        LOG.info("Got result - " + result);
	    } catch (APIConnectionException e) {
	    	e.printStackTrace();
	    	LOG.error("Connection error, should retry later", e);
	    } catch (APIRequestException e) {
	    	e.printStackTrace();
	        LOG.error("Should review the error, and fix the request", e);
	        LOG.info("HTTP Status: " + e.getStatus());
	        LOG.info("Error Code: " + e.getErrorCode());
	        LOG.info("Error Message: " + e.getErrorMessage());
	    }*/
	}
	 public static PushPayload buildPushObject_all_all_alert(String alert) {
//		 Audience.registrationId(registrationId)
		 return PushPayload.newBuilder()
	                .setPlatform(Platform.android())
	                .setAudience(Audience.tag("zcq"))
	                .setNotification(Notification.android(alert, alert, null))
	                .build();
	    }
}
